home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / cgi.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  6.9 KB  |  322 lines

  1. /*
  2.  * $Id: cgi.trm,v 1.7 1995/12/20 21:47:41 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - cgi.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993 Ronald Florence
  9.  *
  10.  * Permission is hereby granted for unlimited non-commercial
  11.  * use of this code, on condition that the copyright
  12.  * notices are left intact and any modifications to the source
  13.  * code are noted as such.  No warranty of any kind is implied
  14.  * or granted for this material.
  15.  *
  16.  * This file is included by ../term.h.
  17.  *
  18.  * This terminal driver supports SCO CGI drivers
  19.  *
  20.  * AUTHOR
  21.  *   Ronald Florence <ron@mlfarm.com>
  22.  */
  23.  
  24. /*
  25.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  26.  */
  27.  
  28. #ifndef GOT_DRIVER_H
  29. #include "driver.h"
  30. #endif
  31.  
  32. #ifdef TERM_REGISTER
  33. register_term(cgi)
  34. register_term(hcgi)
  35. #endif
  36.  
  37. #ifdef TERM_PROTO
  38. TERM_PUBLIC void CGI_init __P((void));
  39. TERM_PUBLIC void HCGI_init __P((void));
  40. TERM_PUBLIC void CGI_graphics __P((void));
  41. TERM_PUBLIC void CGI_text __P((void));
  42. TERM_PUBLIC void CGI_reset __P((void));
  43. TERM_PUBLIC void CGI_move __P((unsigned int x, unsigned int y));
  44. TERM_PUBLIC void CGI_vector __P((unsigned int x, unsigned int y));
  45. TERM_PUBLIC void CGI_linetype __P((int linetype));
  46. TERM_PUBLIC void CGI_put_text __P((unsigned int x, unsigned int y, char *str));
  47. TERM_PUBLIC int CGI_text_angle __P((int ang));
  48. TERM_PUBLIC int CGI_justify_text __P((enum JUSTIFY mode));
  49. TERM_PUBLIC void CGI_point __P((unsigned int x, unsigned int y, int num));
  50. #define CGI_XMAX    32767
  51. #define CGI_YMAX    32767
  52. #define CGI_VTIC    (CGI_YMAX / 75)
  53. #define CGI_HTIC    term->h_tic
  54. #define CGI_VCHAR    term->v_char
  55. #define CGI_HCHAR    term->h_char
  56. #endif
  57.  
  58. #ifndef TERM_PROTO_ONLY
  59. #ifdef TERM_BODY
  60.  
  61. #ifdef VGA_MONO
  62. static short rgb[16][3] = {
  63.   0,    0,      0,      /* Black        */
  64.   1000,    1000,    1000,    /* White    */
  65.   800,    800,    0,    /* Red        */
  66.   0,    600,    0,    /* Green    */
  67.   0,    800,    800,    /* Blue        */
  68.   1000,    1000,    400,    /* Yellow    */
  69.   0,    600,    600,    /* Cyan        */
  70.   600,    600,    600,    /* Magenta    */
  71.   800,    800,    0,    /* Brown    */
  72.   600,    600,    600,    /* Lt. Grey    */
  73.   400,    600,    400,    /* Dark Grey    */
  74.   400,    600,    1000,    /* Lt. Blue    */
  75.   400,    1000,    400,    /* Lt Green    */
  76.   400,    1000,    1000,    /* Lt Cyan    */
  77.   1000,    600,    400,    /* Lt Red    */
  78.   600,    600,    1000    /* Lt Magenta    */
  79. };
  80. #endif
  81.  
  82. #define CRT        (gout[45] == 0)
  83. #define CGICOLORS    gout[13]
  84. #define CGILINES    gout[6]
  85. #define CGIROTATES    gout[36]
  86. #define CGITEXTALIGN    gout[48]
  87.  
  88. static short gout[66];
  89. static short cgidev;
  90. static short vect[4];
  91. static short gin[19] = {
  92.  0,    /* default aspect ratio */
  93.  1,    /* solid line */
  94.  1,    /* line color */
  95.  1,    /* marker type . */
  96.  1,    /* marker color */
  97.  1,    /* graphics text font */
  98.  1,    /* graphics text color */
  99.  0,    /* fill interior style */
  100.  0,    /* fill style index */
  101.  1,    /* fill color index */
  102.  1     /* prompt for paper changes */
  103.  };
  104.  
  105. char    *cgidriver, *getenv();
  106.  
  107.  
  108. TERM_PUBLIC void CGI_init()
  109. {
  110.   if (getenv(cgidriver = "CGIDISP") == NULL)
  111.     HCGI_init();
  112. }
  113.  
  114.  
  115. TERM_PUBLIC void HCGI_init()
  116. {
  117.   if (getenv(cgidriver = "CGIPRNT") == NULL)
  118.     int_error("no CGI driver", NO_CARET);
  119. }
  120.  
  121.  
  122. TERM_PUBLIC void CGI_graphics()
  123. {
  124.   int    i, aspect;
  125.   char *s;
  126.   short font_cap[9];
  127.   char    err_str[80];
  128.  
  129.   if ( (s=getenv("ASPECT")) != NULL && (aspect=atoi(s)) >= 0 && aspect <= 3 )
  130.     gin[0] = aspect;
  131.   for (i = 0; cgidriver[i]; i++) 
  132.     gin[11+i] = cgidriver[i];
  133.   gin[18] = ' ';
  134.  
  135.   if (v_opnwk(gin, &cgidev, gout) < 0) 
  136.     {
  137.       sprintf(err_str, "CGI error %d opening %s", -vq_error(), cgidriver);
  138.       int_error(err_str, NO_CARET);
  139.     }
  140.   vqt_representation(cgidev, 9, font_cap);
  141.   CGI_VCHAR = font_cap[8] * 3 / 2;
  142.   CGI_HCHAR = font_cap[7];
  143.   CGI_HTIC = CGI_VTIC * ((double) gout[1] / (double) gout[4]) / 
  144.             ((double) gout[0] / (double) gout[3]);
  145. #ifdef VGA_MONO
  146.   if (CGICOLORS > 2)
  147.     vsc_table(cgidev, 0, CGICOLORS, rgb);
  148. #endif
  149. }
  150.  
  151.  
  152. TERM_PUBLIC void CGI_text()
  153. {
  154.   if (CRT)  
  155.     {
  156.       short ptin[2];
  157.       char  strin[2];
  158.       
  159.       ptin[0] = 0;
  160.       ptin[1] = 0;
  161.       vrq_string(cgidev, 1, 0, ptin, strin);
  162.     }
  163.   v_clswk(cgidev);
  164. }
  165.  
  166.  
  167. TERM_PUBLIC void CGI_reset()
  168. {
  169. }
  170.  
  171.  
  172. TERM_PUBLIC void CGI_move(x, y)
  173.      unsigned int x, y;
  174. {
  175.   vect[0] = x;
  176.   vect[1] = y;
  177. }
  178.  
  179. TERM_PUBLIC void CGI_vector(x, y)
  180.      unsigned int x, y;
  181. {
  182.   vect[2] = x;
  183.   vect[3] = y;
  184.   v_pline(cgidev, 2, vect);
  185.   vect[0] = x;
  186.   vect[1] = y;
  187. }
  188.  
  189.  
  190. TERM_PUBLIC void CGI_linetype(linetype)
  191.      int linetype;
  192. {
  193.   short lcolor;
  194.  
  195.   if (CGICOLORS > 2) 
  196.     {
  197.       lcolor = (linetype + 2) % CGICOLORS + 1;
  198.       vsl_color(cgidev, lcolor);
  199.       vsm_color(cgidev, lcolor);
  200.     }
  201.   vsl_type(cgidev, (linetype < 1) ? 1 : (linetype % CGILINES) + 1);
  202. }
  203.  
  204.  
  205. TERM_PUBLIC void CGI_put_text(x, y, str)
  206. unsigned int x, y;
  207. char *str;
  208. {
  209.   v_gtext(cgidev, (short) x, (short) y, str);
  210. }
  211.  
  212.  
  213. TERM_PUBLIC CGI_text_angle(ang)
  214. int    ang;
  215. {
  216.   if (!CGIROTATES)
  217.     return FALSE;
  218.                 /* angles are 1/10 degree ccw */
  219.   vst_rotation(cgidev, (ang) ? 900 : 0);
  220.   return TRUE;
  221. }
  222.  
  223.  
  224. TERM_PUBLIC CGI_justify_text(mode)
  225. enum JUSTIFY mode;
  226. {
  227.   short hor_in, hor_out, vert_out;
  228.  
  229.   if (!CGITEXTALIGN)
  230.     return FALSE;
  231.  
  232.   switch (mode)
  233.     {
  234.     case LEFT:   hor_in = 0; break;
  235.     case CENTRE: hor_in = 1; break;
  236.     case RIGHT:  hor_in = 2; break;
  237.     }
  238.   vst_alignment(cgidev, hor_in, 1, &hor_out, &vert_out); 
  239.   return TRUE;
  240. }
  241.  
  242.  
  243. #define POINT_TYPES 6
  244.  
  245. TERM_PUBLIC void CGI_point(x,y,num)
  246.      unsigned int x, y;
  247.      int num;
  248. {
  249.   short  point[2];
  250.   static short cgimarker[POINT_TYPES] = {1, 2, 6, 4, 5, 3};
  251.                           /* .  +  <> [] X  * */
  252.   if (num < 0)
  253.     {
  254.       CGI_move(x, y);
  255.       CGI_vector(x, y);
  256.     }
  257.   else
  258.     {
  259.       vsm_type(cgidev, cgimarker[num % POINT_TYPES]);
  260.       point[0] = x;
  261.       point[1] = y;
  262.       v_pmarker(cgidev, 1, point);
  263.     }
  264. }
  265.  
  266. #endif /* TERM_BODY */
  267.  
  268. #ifdef TERM_TABLE
  269.  
  270. TERM_TABLE_START(cgi_driver)
  271.     "cgi", "SCO CGI drivers (requires CGIDISP or CGIPRNT env variable)",
  272.        CGI_XMAX, CGI_YMAX, 0, 0, 
  273.        CGI_VTIC, 0, options_null, CGI_init, CGI_reset, 
  274.        CGI_text, null_scale, CGI_graphics, CGI_move, CGI_vector, 
  275.        CGI_linetype, CGI_put_text, CGI_text_angle, 
  276.        CGI_justify_text, CGI_point, do_arrow, set_font_null
  277. TERM_TABLE_END(cgi_driver)
  278.  
  279. #undef LAST_TERM
  280. #define LAST_TERM cgi_driver
  281.  
  282. TERM_TABLE_START(hcgi_driver)
  283.     "hcgi", "SCO CGI drivers (hardcopy, requires CGIPRNT env variable)",
  284.        CGI_XMAX, CGI_YMAX, 0, 0, 
  285.        CGI_VTIC, 0, options_null, HCGI_init, CGI_reset, 
  286.        CGI_text, null_scale, CGI_graphics, CGI_move, CGI_vector, 
  287.        CGI_linetype, CGI_put_text, CGI_text_angle, 
  288.        CGI_justify_text, CGI_point, do_arrow, set_font_null
  289. TERM_TABLE_END(hcgi_driver)
  290.  
  291. #undef LAST_TERM
  292. #define LAST_TERM hcgi_driver
  293.  
  294. #endif /* TERM_TABLE */
  295. #endif /* TERM_PROTO_ONLY */
  296.  
  297. /*
  298.  * NAME: cgi
  299.  *
  300.  * OPTIONS: none
  301.  *
  302.  * SUPPORTS: SCO CGI drivers
  303.  *
  304.  * Further Info: Requires environment variables to be set. CGIDISP 
  305.  *         to display the plot or CGIPRNT to send it to a 
  306.  *         printer.
  307.  *         There is another terminal for hardcopys (hcgi).
  308.  *
  309.  */
  310.  
  311. /*
  312.  * NAME: hcgi
  313.  *
  314.  * OPTIONS: none
  315.  *
  316.  * SUPPORTS: SCO CGI drivers hardcopy
  317.  *
  318.  * Further Info: Requires environment variable CGIPRNT to be set 
  319.  *         to send the plot to the right printer.
  320.  *         There is another terminal for displays (cgi).
  321.  *
  322.  */